<?php
session_save_path('sessions');
session_start();

include("include/dbUserTypes.php");

// Include our user class
include_once("include/user.php");

// Create a variable to store our user if we're validated
$user = null;

// Check if we're in a valid session. If not, go back to main login page.

if( !isset($_SESSION['user']) || $_SESSION['user'] == null ) {
    header("location:main_login.php");
}
else {
    // Unserialize our user to turn it back into a useful object
    $user = unserialize($_SESSION['user']);
}

// If we're not a business (or admin) go back to the user redirection page
if( $user->getUserType() != $USERTYPE_REGISTERED && $user->getUserType() != $USERTYPE_ADMIN)
    header("location:login_success.php");


// Include the header (CSS files, etc)
include("include/dbconnection.php");
include("include/header.php"); ?>


<body>
  <div id="wrapper">
    <div id="header"> </div>
    <div id="left">
      <div id="logo">
        <h1>Home Sale</h1>
        <p>Only By Owner</p>
      </div>
      <div id="nav">
        <ul>
          <li >
            <a href="addAhomeForSale.php">Add a House for sale</a>
          </li>
          <li >
            <a href="updateAhome.php">Update House information</a>
          </li>
          <li >
            <a href="updateAhomePicture.php">Update House picture</a>
          </li>
          <li>
            <a href="searchhouse.php">Search House</a>
          </li>
          <li class="important">
            <a href="emailMenu.php">Mailbox</a>
          </li>
          <li>
            <a href="logout.php">Logout</a>
          </li>
        </ul>
      </div>
      <div id="news">
        <?php include("adgeneratorleft1.php");?>
        <div class="hr-dots"> </div>
        <?php include("adgeneratorleft2.php");?>
      </div>
      <div id="support">
      </div>
    </div>
    <div id="right">
      <h2>Message Content</h2>
      <div id="welcome">

        <?php

		$currentUser = $user->getUserID();
    $messageNumber = $_GET['messageNumber'];
			$emailQuery = mysql_query("select * from mailbox where messageNumber = $messageNumber and userID = $currentUser");

			$row1 = mysql_fetch_array($emailQuery);

        $userID = $row1['userID'];
				$senderID = $row1['senderID'];
				$messageSubject = $row1['messageSubject'];
        $messageContent = $row1['messageContent'];


      $senderNameQuery = mysql_query("select * from users where userID = $senderID");
      $row2 = mysql_fetch_array($senderNameQuery);
          $senderName = $row2['username'];
				?>

                  <p>Message from <?php echo $senderName ?></p>
                  <p>Subject: <?php echo $messageSubject?></p>
                  <br></br>
                  <p><?php echo $messageContent?></p>

        <table>
          <form name="myForm" action="emailMenuReplyMessage.php" method="post">
            <input type="hidden" name="userID" value ="<?php echo $userID?>">
            <input type="hidden" name="senderID" value ="<?php echo $senderID?>">
            <input type="hidden" name="messageSubject" value ="<?php echo $messageSubject?>">
            <input type="hidden" name="messageContent" value ="<?php echo $messageContent?>">

            <tr>
              <td>
                <input type="submit" value="Reply" />
              </td>
            </tr>
              <?php

				        mysql_close();

				      ?>
          </table>


      </div>
      <h3></h3>
        <div id="corp">
          <?php include("adgeneratorbottomleft.php");?>
        </div>
        <div id="indu">
          <?php include("adgeneratorbottomright.php");?>
        </div>
    </div>
    <div class="clear"> </div>
    <div id="spacer"> </div>
    <div id="footer">
      <div id="copyright">
        &copy; Template taken from http://www.freewebsitetemplates.com/
      </div>
      <div id="footerline"></div>
    </div>

  </div>
</body>